//
//  HFViewController.m
//  Deepbreathing
//
//  Created by rimi on 15/9/10.
//  Copyright (c) 2015年 DreamHack. All rights reserved.
//
//
/*

 参与者的值还没有搞定；
*/
#import "HFViewController.h"
#import "HFTopView.h"
#import "HFTopTableViewCell.h"
#import "CYYNetWorkManager+CommentList.h"
#import "CYYNetWorkManager+PartyParticipatorsList.h"
#import "CYYNetWorkManager+PartyDetail.h"
#import "CYYNetWorkManager+takePartyInAParty.h"
#import "CYYNetWorkManager+ObserveAParty.h"
#import "CYYCommentListViewController.h"
#import "CYYEditMyPartyViewController.h"
#import "MLParticipantsViewController.h"
#import "CYYNetWorkManager+CommentList.h"

@interface HFViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) HFTopView *backView;
@property(strong, nonatomic) UITableView *tableView;
@property (strong, nonatomic) NSMutableArray *dataSource;
@property (strong, nonatomic) NSMutableArray *activeFollowsDataSource;
@property (strong, nonatomic) NSMutableArray *partyDetialDataSource;
@property (strong, nonatomic) UIButton *leftNavButton;
@property (strong, nonatomic) UIButton *rightNavButton;
@property (strong, nonatomic) NSDictionary *stringDict;//存自适应的值

@property (strong, nonatomic) UIButton *attentionButton;//关注
@property (strong, nonatomic) UIButton *participationButton;//参与
@property (strong, nonatomic) UIDynamicAnimator *animator;
@property (strong, nonatomic) UIButton *editButton;
@property (assign, nonatomic) NSString  *statusBegainString;// 状态
@property (assign, nonatomic) NSString *statusEndString;// 状态
@property (strong, nonatomic) UIScrollView *myScrolleView;
@property (nonatomic, strong) GmailLikeLoadingView *loadingView;
@property (strong, nonatomic) UILabel *bartitleLabel;
@property (nonatomic, copy) NSString *peopleStr;
@property (strong, nonatomic) UIButton *deleteButton;

- (void)initializeUserInterface;
- (void)initializeDataSource;
@end

@implementation HFViewController
-(void)dealloc{
//    NSLog(@"%s",__func__);
}
- (void)viewDidLoad {
    
    
    
    
    
    
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 63, 320, 0.5) adjustWidth:YES];
        view.backgroundColor = [UIColor grayColor];
        [self.view addSubview:view];

//  self.view.backgroundColor = [UIColor colorWithRed:228 / 255.0 green:215 / 255.0 blue:223 / 255.0 alpha:1];
    
   
    [self.view addSubview:self.leftNavButton];
    [self.view addSubview:self.editButton];
    [self.view addSubview:self.bartitleLabel];
    self.bartitleLabel.text = @"活动详情";
    [self.view addSubview:self.rightNavButton];
    [self.view addSubview:self.deleteButton];
    
    
    if ([self.laucher isEqualToString:@"自己"]) {
        
        self.editButton.hidden = NO;
        self.rightNavButton.hidden = YES;
    } else {
        self.editButton.hidden = YES;
        self.rightNavButton.hidden = NO;
    
    }
    if ([self.status isEqualToString:@"已取消"] || [self.status isEqualToString:@"已过期"]) {
        self.deleteButton.hidden = NO;
        self.editButton.hidden = YES;
        self.rightNavButton.hidden= YES;
        
    }
    __weak typeof(self) myVC = self;
    [CYYNetWorkManager newPartyParticipatorsListWithPartyObjectId:self.partyObjectId sucess:^(NSArray *array) {
        
//        NSLOG_CLASSNAME;
//        NSLog(@"网路请求参与人列表的返回array是============%@",array);
        
        if (array != nil) {
           _peopleStr = @"";
            for (NSDictionary *people in array) {
                
               NSString *arrayp = [people objectForKey:@"name"];
            
                _peopleStr = [arrayp stringByAppendingString:[NSString stringWithFormat:@"  %@", _peopleStr]];
         
            }
            
//            NSLog(@"拼接后的参与人列表的返回array是============%@",_peopleStr);
            
            myVC.stringDict = @{@"address":myVC.partyPositionNameString,@"detial":myVC.partyDetailString,@"partyTitle":myVC.partyTitleString,@"participator":myVC.partyParticipatorsNumber,@"laucher":myVC.laucher, @"people":myVC.peopleStr, @"SecretCode":myVC.partySecretCode};
            
            
            myVC.backView.originatorLabel.text = myVC.laucher;
            
            
            //            weakSelf.backView.titleLabel.text = [object objectForKey:@"partyTitle"];
            myVC.backView.timeLabel.text = [NSString stringWithFormat:@"%@—%@",myVC.partyBeginTimeString , myVC.partyEndTimeString];
            myVC.backView.addressString = myVC.partyPositionNameString;
            //            NSLog(@"------r000%@", self.backView.addressString);
            
            
            myVC.backView.addressLabel.text =  myVC.partyPositionNameString;
            
            
            
            
            
            
            if (myVC.backView.frame.size.height > 1) {
                
                [myVC.view addSubview:myVC.loadingView];
                [myVC.loadingView setHidden:NO];
                [myVC.loadingView startAnimating];
                
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [myVC.loadingView setHidden:YES];
                    [myVC.loadingView stopAnimating];
                    [myVC initializeDataSource];
                    [myVC initializeUserInterface];

                });

                
                
                [myVC.backView.addressButton addTarget:myVC action:@selector(respondToAddressButton:) forControlEvents:UIControlEventTouchUpInside];
                
                [myVC.backView.peoplesButton addTarget:myVC action:@selector(respondToPeoplesButton:) forControlEvents:UIControlEventTouchUpInside];
                
                [myVC.backView.massageBoardButton addTarget:myVC action:@selector(respondToMassageBoardButton:) forControlEvents:UIControlEventTouchUpInside];
            } else {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"网络异常" delegate:myVC cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                [alert show];
                
                
            }
            
            //放最后
            
            
            __weak typeof(self) mySVC = self;
            [CYYNetWorkManager newCommentListWithPartyObjectId:mySVC.partyObjectId sucess:^(NSArray *array) {
//                NSLog(@"%@", array);
                _dataSource = [array mutableCopy];
                if (_dataSource.count > 3) {
                    _dataSource = [[_dataSource subarrayWithRange:NSMakeRange(0, 3)] mutableCopy];
                }
                
                if (mySVC.backView) {
                    [mySVC.tableView reloadData];
                }
                
                
            } fail:^(NSError *error) {
                
            }];

        

            
        } else {
            
        
        }
    } fail:^(NSError *error) {
        
    }];
    
    
    
    

}



#pragma mark - callBack/action'

- (void)respondToDeleteButton:(UIButton *)sender
{
     __weak typeof(self) myVC = self;
    [CYYNetWorkManager deleteTarkPartInPartyithObjectId:myVC.partyObjectId sucess:^(NSString *sucessString) {
        
        [myVC.navigationController popViewControllerAnimated:YES];
        
        
    } fail:^(NSError *error) {
        
    }];



    
}

//编辑
- (void)respondToEditButton:(UIButton *)sender{
    CYYEditMyPartyViewController * editMyPartyVC = [[CYYEditMyPartyViewController alloc]init];
    editMyPartyVC.partyObjectId = self.partyObjectId;
    editMyPartyVC.partyTitleString = self.partyTitleString;
    editMyPartyVC.partyDetailString = self.partyDetailString;
    editMyPartyVC.partyBeginTimeString = self.partyBeginTimeString;
    editMyPartyVC.partyEndTimeString = self.partyEndTimeString;
    editMyPartyVC.partyPositionNameString = self.partyPositionNameString;
    [[[ControllerManager sharedManager] rootViewController] pushViewController:editMyPartyVC animated:YES];
}

//关注
- (void)respondToAttentionButton:(UIButton *)sender
{
    self.attentionButton.userInteractionEnabled = NO;//关闭交互
    self.participationButton.userInteractionEnabled = NO;
    sender.selected = !sender.selected;
    if (self.attentionButton.selected == YES) {
        self.attentionButton.backgroundColor = [UIColor grayColor];
        self.participationButton.selected = NO;
        self.participationButton.backgroundColor = COLOR_TagGreen;
    } else {
        self.attentionButton.backgroundColor = COLOR_TagBlue;
//        self.participationButton.selected = YES;
//        self.participationButton.backgroundColor = [UIColor grayColor];

    }
    
       if (sender.selected == YES) {
        self.backView.titleJoinLabel.text = @"已关注";
    }
    
    if (self.attentionButton.selected == NO && self.participationButton.selected == NO) {
        self.backView.titleJoinLabel.hidden = YES;
    }
    
    if (self.attentionButton.selected == YES || self.participationButton.selected == YES) {
        self.backView.titleJoinLabel.hidden = NO;
    }
    
    
    //处理记录按钮变化
    
    
    if (self.participationButton.selected == YES) {
        _statusEndString = @"已参加";
    }
    
    if (self.attentionButton.selected == YES) {
        _statusEndString = @"已关注";
    }
    
    if (self.attentionButton.selected == NO && self.participationButton.selected == NO
        ) {
        _statusEndString = @"未关注";
    }
    
    if (self.attentionButton.enabled == NO && self.participationButton.enabled == NO) {
        _statusEndString = @"已取消";
    }

    if (sender.selected == YES) {
        __weak typeof(self) myVC = self;
        [CYYNetWorkManager observeAPartyWithObjectId:myVC.partyObjectId sucess:^(NSString *sucessString) {
            myVC.attentionButton.userInteractionEnabled = YES;
            myVC.participationButton.userInteractionEnabled = YES;
        } fail:^(NSError *error) {
            myVC.attentionButton.userInteractionEnabled = YES;//交互
            myVC.participationButton.userInteractionEnabled = YES;
        }];
        [CYYNetWorkManager deleteTarkPartInPartyithObjectId:myVC.partyObjectId sucess:^(NSString *sucessString) {
            myVC.attentionButton.userInteractionEnabled = YES;//交互
            myVC.participationButton.userInteractionEnabled = YES;
        } fail:^(NSError *error) {
            myVC.attentionButton.userInteractionEnabled = YES;//交互
            myVC.participationButton.userInteractionEnabled = YES;
        }];
        

    } else {
        __weak typeof(self) myVC = self;
        [CYYNetWorkManager deleteObservePartyWithObjectId:myVC.partyObjectId sucess:^(NSString *sucessString) {
            myVC.attentionButton.userInteractionEnabled = YES;//交互
            myVC.participationButton.userInteractionEnabled = YES;
        } fail:^(NSError *error) {
            myVC.attentionButton.userInteractionEnabled = YES;//交互
            myVC.participationButton.userInteractionEnabled = YES;
        }];
       
        
        [CYYNetWorkManager takePartyInAPartyWithPartyObjectId:myVC.partyObjectId sucess:^(NSString *sucessString) {
            myVC.attentionButton.userInteractionEnabled = YES;//交互
            myVC.participationButton.userInteractionEnabled = YES;
        } fail:^(NSError *error) {
            myVC.attentionButton.userInteractionEnabled = YES;//交互
            myVC.participationButton.userInteractionEnabled = YES;
        }];

    
    }
    
    
    
    //实验
    self.backView.titleJoinLabel.backgroundColor = COLOR_TagBlue;
    
    
    
}

//参加
- (void)respondToParticpationButton:(UIButton *)sender
{
    self.attentionButton.userInteractionEnabled = NO;//关闭交互
    self.participationButton.userInteractionEnabled = NO;
    self.loadingView.hidden = NO;
    [self.loadingView startAnimating];
    sender.selected = !sender.selected;
    
    if (self.participationButton.selected == YES) {
        self.participationButton.backgroundColor = [UIColor grayColor];
        self.attentionButton.selected = NO;
        self.attentionButton.backgroundColor = COLOR_TagBlue;

    } else {
        self.participationButton.backgroundColor = COLOR_TagGreen;
//        self.attentionButton.selected = YES;
//        self.attentionButton.backgroundColor = [UIColor grayColor];

    }
    
    if (sender.selected == YES) {
        self.backView.titleJoinLabel.text = @"已参加";
    }
    
    if (self.attentionButton.selected == NO && self.participationButton.selected == NO) {
        self.backView.titleJoinLabel.hidden = YES;
    }
    
    if (self.attentionButton.selected == YES || self.participationButton.selected == YES) {
        self.backView.titleJoinLabel.hidden = NO;
    }
    
    //处理记录按钮变化
    
    
    if (self.participationButton.selected == YES) {
        _statusEndString = @"已参加";
    }
    
    if (self.attentionButton.selected == YES) {
        _statusEndString = @"已关注";
    }
    
    if (self.attentionButton.selected == NO && self.participationButton.selected == NO
        ) {
        _statusEndString = @"未关注";
    }
    
    if (self.attentionButton.enabled == NO && self.participationButton.enabled == NO) {
        _statusEndString = @"已取消";
    }
    
    
   // 实验
    __weak typeof(self) myVC = self;
    if (sender.selected == YES) {
        [CYYNetWorkManager takePartyInAPartyWithPartyObjectId:self.partyObjectId sucess:^(NSString *sucessString) {
            myVC.attentionButton.userInteractionEnabled = YES;//交互
            myVC.participationButton.userInteractionEnabled = YES;
        } fail:^(NSError *error) {
            myVC.attentionButton.userInteractionEnabled = YES;//交互
            myVC.participationButton.userInteractionEnabled = YES;
        }];
        [CYYNetWorkManager deleteObservePartyWithObjectId:self.partyObjectId sucess:^(NSString *sucessString) {
            myVC.attentionButton.userInteractionEnabled = YES;//交互
            myVC.participationButton.userInteractionEnabled = YES;
        } fail:^(NSError *error) {
            myVC.attentionButton.userInteractionEnabled = YES;//交互
            myVC.participationButton.userInteractionEnabled = YES;
        }];
        
    } else {
        [CYYNetWorkManager deleteTarkPartInPartyithObjectId:self.partyObjectId sucess:^(NSString *sucessString) {
            myVC.attentionButton.userInteractionEnabled = YES;//交互
            myVC.participationButton.userInteractionEnabled = YES;
        } fail:^(NSError *error) {
            myVC.attentionButton.userInteractionEnabled = YES;//交互
            myVC.participationButton.userInteractionEnabled = YES;
        }];
        [CYYNetWorkManager observeAPartyWithObjectId:self.partyObjectId sucess:^(NSString *sucessString) {
            myVC.attentionButton.userInteractionEnabled = YES;//交互
            myVC.participationButton.userInteractionEnabled = YES;
        } fail:^(NSError *error) {
            myVC.attentionButton.userInteractionEnabled = YES;//交互
            myVC.participationButton.userInteractionEnabled = YES;
        }];
    
    }
    
    

    self.backView.titleJoinLabel.backgroundColor = COLOR_TagGreen;


}
//地图
- (void)respondToAddressButton:(UIButton *)sender
{
//    NSLog(@"111111111111");
    
//    HFMapViewController *mapView = [[HFMapViewController alloc] init];
//    [self.navigationController pushViewController:mapView animated:YES];

}
// 和已参加人数一行的
- (void)respondToPeoplesButton:(UIButton *)sender
{
    MLParticipantsViewController *MLVc = [[MLParticipantsViewController alloc] init];
    
    [self.navigationController pushViewController:MLVc animated:YES];
    MLVc.partyObjectId = self.partyObjectId;
    MLVc.headerTitleStr = self.partyTitleString;
    if (self.participationButton.selected == YES) {
        MLVc.isParticipate = YES;
    } else {
        MLVc.isParticipate = NO;
    
    
    }
    
    
//    NSLog(@"22222222222");
    
    
}
// 留言板一行的
- (void)respondToMassageBoardButton:(UIButton *)sender
{
//     NSLog(@"33333333333333");
    CYYCommentListViewController * commentListVC = [[CYYCommentListViewController alloc]init];
    commentListVC.partyObjectId = self.partyObjectId;
    [[[ControllerManager sharedManager] rootViewController] pushViewController:commentListVC animated:YES];
    
}
//返回
- (void)respondToBackButton:(UIButton *)sender
{
   
    [self.navigationController popViewControllerAnimated:YES];

    if ([self.laucher isEqualToString:@"自己"]) {
        return;
    }
    
    if ([_statusEndString isEqualToString:_statusBegainString]) {
        return;
    }
    
    if (self.participationButton.selected == YES) {
//                [CYYNetWorkManager takePartyInAPartyWithPartyObjectId:self.partyObjectId sucess:^(NSString *sucessString) {
//        
//                } fail:^(NSError *error) {
//        
//                }];
    }
    
    else if (self.attentionButton.selected == YES) {
//                [CYYNetWorkManager observeAPartyWithObjectId:self.partyObjectId sucess:^(NSString *sucessString) {
//        
//                } fail:^(NSError *error) {
//        
//                }];
    }
    else if (self.participationButton.selected == NO && self.attentionButton.selected == NO) {
        
        if ([_statusBegainString isEqualToString:@"已参加"]) {
            
            [CYYNetWorkManager deleteTarkPartInPartyithObjectId:self.partyObjectId sucess:^(NSString *sucessString) {
                
                        } fail:^(NSError *error) {
                
                        }];

            
            
            
            
        } else if([_statusBegainString isEqualToString:@"已关注"])
        {
            [CYYNetWorkManager deleteObservePartyWithObjectId:self.partyObjectId sucess:^(NSString *sucessString) {
                
            } fail:^(NSError *error) {
                
            }];

        
        
        }
        
        
        
    } else if (self.participationButton.enabled == NO)
    {
        
                 return;
        
    }
    
    

}
//右边
- (void)respondToRightButton:(UIButton *)sender
{
    
    UserModel *model = [UserModel defaultUser];
    if ([model isAlreadyLoad] == NO) {
         [[[ControllerManager sharedManager] rootViewController]presentViewController:[ControllerManager sharedManager].loadViewController animated:YES completion:nil];
        
        return;
    }
    
    sender.selected = !sender.selected;
    if (sender.selected) {
        
        [UIView animateWithDuration:0.1 animations:^{
            sender.transform = CGAffineTransformMakeRotation(M_PI / 4);
        }];
        
        [self.animator removeAllBehaviors];

        self.participationButton.hidden = NO;
        self.attentionButton.hidden = NO;
        CGPoint point = CGPointMake(235*DHFlexibleHorizontalMutiplier(), 60*DHFlexibleHorizontalMutiplier());
        
        UISnapBehavior *snap = [[UISnapBehavior alloc] initWithItem:self.participationButton snapToPoint:point];
        
        
        snap.damping = 0.5;
//        [self.animator removeAllBehaviors];
        [self.animator addBehavior:snap];
        
        
        CGPoint point1 = CGPointMake(280 *DHFlexibleHorizontalMutiplier(), 100*DHFlexibleHorizontalMutiplier());
        UISnapBehavior *snapb = [[UISnapBehavior alloc] initWithItem:self.attentionButton snapToPoint:point1];
        snapb.damping = 0.5;
//            [self.animator removeAllBehaviors];
        [self.animator addBehavior:snapb];
        

        
     
    }
    
    if (!sender.selected) {
        [UIView animateWithDuration:0.1 animations:^{
            sender.transform = CGAffineTransformMakeRotation(0);
        }];
        
        CGPoint point = CGPointMake(280*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier());
        
        UISnapBehavior *snap = [[UISnapBehavior alloc] initWithItem:self.participationButton snapToPoint:point];
        
        
        snap.damping = 0.5;
                [self.animator removeAllBehaviors];
        [self.animator addBehavior:snap];
        
        
        CGPoint point1 = CGPointMake(280 *DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier());
        UISnapBehavior *snapb = [[UISnapBehavior alloc] initWithItem:self.attentionButton snapToPoint:point1];
        snapb.damping = 0.5;
        //            [self.animator removeAllBehaviors];
        [self.animator addBehavior:snapb];
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            self.participationButton.hidden = YES;
            self.attentionButton.hidden = YES;

        });
        

                
    }
    
    
}
#pragma mark - init
- (void)initializeDataSource
{

    
    self.backView.titleJoinLabel.text = self.status;
//    NSLog(@"%@", self.laucher);
    
    //已经参加人数
    __weak typeof(self) myVC = self;
    [CYYNetWorkManager partyParticipatorsNumberWithPartyObjectId:self.partyObjectId sucess:^(NSInteger partyParticipatorsNumber) {
        NSInteger i = partyParticipatorsNumber;
        myVC.backView.numberLabel.text = [NSString stringWithFormat:@"%ld", (long)i];
        
    } fail:^(NSError *error) {
        
    }];
    
    
    //partydetial的数据
    __weak typeof(self) mySVC = self;
    [CYYNetWorkManager partyStateWithPartyObjectId:_partyObjectId sucess:^(NSString *sucessString) {
//        NSLog(@"%@", sucessString);
        if ([sucessString isEqualToString:@"已取消"]) {
            // 该cell的所有字变灰色
            mySVC.backView.titleJoinLabel.text = sucessString;
        } else if ([sucessString isEqualToString:@"已参加"]){
           self.backView.titleJoinLabel.text = sucessString;
            mySVC.backView.titleJoinLabel.backgroundColor = COLOR_TagGreen;
        } else if ([sucessString isEqualToString:@"已关注"]){
             mySVC.backView.titleJoinLabel.text = sucessString;
            mySVC.backView.titleJoinLabel.backgroundColor = COLOR_TagBlue;
        } else if([sucessString isEqualToString:@"未关注"])
        {
            mySVC.backView.titleJoinLabel.backgroundColor = COLOR_BackgroundGray;
            
         self.backView.titleJoinLabel.text = sucessString;
            mySVC.backView.titleJoinLabel.backgroundColor = [UIColor grayColor];

        } else {
             mySVC.backView.titleJoinLabel.backgroundColor = COLOR_BackgroundGray;
        
        }
    } fail:^(NSError *error) {
//        NSLog(@"%@",error);
        UIAlertController *alertVC = [[UIAlertController alloc] init];
        
        [alertVC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
        [mySVC presentViewController:alertVC animated:YES completion:nil];
        
    }];

    
   
}
- (void)initializeUserInterface
{
    
    _myScrolleView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, 320, 568) adjustWidth:NO];
       [self.view addSubview:_myScrolleView];
    [_myScrolleView addSubview:self.backView];
    _myScrolleView.contentSize = CGSizeMake(320, self.backView.frame.origin.y + self.backView.frame.size.height + 240* DHFlexibleHorizontalMutiplier());

//    NSLog(@"65680-0-%@", self.backView);
    if (self.backView) {
        
        
        
       
        self.automaticallyAdjustsScrollViewInsets = NO;
    
               _myScrolleView.backgroundColor = [UIColor whiteColor];

            [_myScrolleView addSubview:self.tableView];
        
        self.tableView.rowHeight = 60 * DHFlexibleVerticalMutiplier();
        [self.view addSubview:self.attentionButton];
        [self.view addSubview:self.participationButton];
        self.attentionButton.hidden = YES;
        self.participationButton.hidden = YES;
        
//

    }
    UIView *views = [[UIView alloc] initWithFrame:CGRectMake(10, self.tableView.frame.origin.y, 300* DHFlexibleHorizontalMutiplier(), 0.5)];
    views.backgroundColor = [UIColor grayColor];
    [_myScrolleView addSubview:views];

    
    
    
    
}
- (HFTopView *)backView
{
    if (!_backView) {
        _backView = [[HFTopView alloc] initWith:self.stringDict];
//        [self.myScrolleView addSubview:_backView];
    }
    return _backView;

}
#pragma mark - sys protocol methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSource.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *const ID = @"ahgas";
    HFTopTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[HFTopTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.timeLabel.text = _dataSource[indexPath.row][@"createdAt"];
        cell.peopleLabel.text = _dataSource[indexPath.row][@"commentAuthorName"];
        cell.contentLabel.text = _dataSource[indexPath.row][@"commentContent"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
//        cell.backgroundColor = [UIColor colorWithRed:228 / 255.0 green:215 / 255.0 blue:223 / 255.0 alpha:1];
//        cell.separatorInset = UIEdgeInsetsMake(10, 10, 10, 10);
       
    }
    
    
    return cell;

}

#pragma mark - getter
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = ({
            UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.backView.frame.size.height, 320*DHFlexibleHorizontalMutiplier(), 240 * DHFlexibleVerticalMutiplier())style:UITableViewStylePlain];
            tableView.delegate = self;
            tableView.dataSource = self;
            tableView.backgroundColor = [UIColor whiteColor];
            [tableView setScrollEnabled:NO];
            tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
            tableView;
        });
    }
    return _tableView;


    
    
}

-(GmailLikeLoadingView *)loadingView{
    if (!_loadingView) {
        _loadingView = [[GmailLikeLoadingView alloc]initWithFrame:CGRectMake(320*0.5 - 12, 568*0.5 - 12, 15, 15) adjustWidth:YES];
        [_loadingView setHidden:YES];
    }
    return _loadingView;
}
-(UILabel *)bartitleLabel{
    if (!_bartitleLabel) {
        _bartitleLabel = [[UILabel alloc]init];
        _bartitleLabel.bounds = DHFlexibleFrame(CGRectMake(0, 0, 180, 44), NO);
        _bartitleLabel.center = DHFlexibleCenter(CGPointMake(320 / 2, 20 + 44 / 2));
        [_bartitleLabel setTextColor:[UIColor blackColor]];
        _bartitleLabel.font = [UIFont systemFontOfSize:20 * DHFlexibleVerticalMutiplier()];
        _bartitleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _bartitleLabel;
}

#pragma mark - 生命周期
- (void)viewWillAppear:(BOOL)animated
{

}
- (void)viewDidAppear:(BOOL)animated
{
    
    if ([self.status isEqualToString:@"已参加"]) {
        
        self.participationButton.selected = YES;
       
        
        
    } else if ([self.status isEqualToString:@"已关注"])
    {
        self.attentionButton.selected = YES;
       
        
        
        
    }  else if([self.status isEqualToString:@"未关注"])
    {
        self.attentionButton.selected = NO;
        self.participationButton.selected = NO;
        
        
        
    } else {
        
        self.attentionButton.enabled = NO;
        self.participationButton.enabled = NO;
        self.attentionButton.titleLabel.textColor = [UIColor blackColor];
        self.participationButton.titleLabel.textColor = [UIColor blackColor];
        

        
    }
    
    if (self.participationButton.selected == YES) {
        _statusBegainString = @"已参加";
    }
    
    if (self.attentionButton.selected == YES) {
        _statusBegainString = @"已关注";
    }
    
    if (self.attentionButton.selected == NO && self.participationButton.selected == NO
) {
        _statusBegainString = @"未关注";
    }
    
    if (self.attentionButton.enabled == NO && self.participationButton.enabled == NO) {
        _statusBegainString = @"已取消";
    }

    
    
    
    
    
    //处理button逻辑
    
    if (self.participationButton.selected) {
        self.participationButton.backgroundColor = [UIColor grayColor];
        self.attentionButton.selected = NO;
        self.attentionButton.backgroundColor = COLOR_TagBlue;
        
    }
    if (self.attentionButton.selected) {
        self.attentionButton.backgroundColor = [UIColor grayColor];
        self.participationButton.selected = NO;
        self.participationButton.backgroundColor = COLOR_TagGreen;
    }
    
    
    if (self.participationButton.selected == NO && self.attentionButton.selected == NO)
    {
        self.attentionButton.backgroundColor = COLOR_TagBlue;
        self.participationButton.backgroundColor = COLOR_TagGreen;
    
    
    }
    
    
    
    

      
    
   

}


- (void)viewWillDisappear:(BOOL)animated
{
    if ([self.laucher isEqualToString:@"自己"]) {
        return;
    }
    
    if ([_statusEndString isEqualToString:_statusBegainString]) {
        return;
    }
    
    if (self.participationButton.selected == YES) {
//        [CYYNetWorkManager takePartyInAPartyWithPartyObjectId:self.partyObjectId sucess:^(NSString *sucessString) {
//            
//        } fail:^(NSError *error) {
//            
//        }];
    }
    
    else if (self.attentionButton.selected == YES) {
//        [CYYNetWorkManager observeAPartyWithObjectId:self.partyObjectId sucess:^(NSString *sucessString) {
//            
//        } fail:^(NSError *error) {
//            
//        }];
    }
    else if (self.participationButton.selected == NO && self.attentionButton.selected == NO) {
        
//        [CYYNetWorkManager deleteObservePartyWithObjectId:self.partyObjectId sucess:^(NSString *sucessString) {
//            
//        } fail:^(NSError *error) {
//            
//        }];
        
        if ([self.status isEqualToString:@"已过期"]) {
            return;
        }
        __weak typeof(self) myVC = self;
//
        [CYYNetWorkManager deleteTarkPartInPartyithObjectId:myVC.partyObjectId sucess:^(NSString *sucessString) {
            
        } fail:^(NSError *error) {
            
        }];
        
        
    } else if (self.participationButton.enabled == NO)
    {
        return;
        
    }
    
    
}


-(UIButton *)leftNavButton{
    if (!_leftNavButton) {
        _leftNavButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_leftNavButton setFrame:DHFlexibleFrame(CGRectMake(15, 30, 20, 20), YES)];
        [_leftNavButton setImage:[UIImage imageNamed:@"iconfont-zuojiantou"] forState:UIControlStateNormal];
        [_leftNavButton addTarget:self action:@selector(respondToBackButton:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _leftNavButton;

}
- (UIButton *)rightNavButton
{
    if (!_rightNavButton) {
        _rightNavButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_rightNavButton setFrame:DHFlexibleFrame(CGRectMake(280, 30, 20, 20), YES)];
        [_rightNavButton setImage:[UIImage imageNamed:@"1001-1"] forState:UIControlStateNormal];
        [_rightNavButton addTarget:self action:@selector(respondToRightButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightNavButton;


}
- (UIButton *)attentionButton
{
   
    if (!_attentionButton) {
        _attentionButton = ({
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setFrame:DHFlexibleFrame(CGRectMake(280, 30, 40, 40), YES)];
            [button setTitle:@"关注" forState:UIControlStateNormal];
            [button setTitle:@"取消\n关注" forState:UIControlStateSelected];
            button.titleLabel.font = [UIFont systemFontOfSize:14 * DHFlexibleHorizontalMutiplier()];
            button.titleLabel.numberOfLines = 2;
            button.layer.cornerRadius = 20 * DHFlexibleHorizontalMutiplier();
            button.clipsToBounds = YES;
//            button.backgroundColor = [UIColor blueColor];
            [button addTarget:self action:@selector(respondToAttentionButton:) forControlEvents:UIControlEventTouchUpInside];
            button;
            
        });
        
    }
    return _attentionButton;

}

- (UIButton *)participationButton
{
       if (!_participationButton) {
        
        _participationButton = ({
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setFrame:DHFlexibleFrame(CGRectMake(280, 30, 40, 40), YES)];
            [button setTitle:@"参加" forState:UIControlStateNormal];
            [button setTitle:@"取消\n参加" forState:UIControlStateSelected];
            button.titleLabel.font = [UIFont systemFontOfSize:10 * DHFlexibleHorizontalMutiplier()];
            button.titleLabel.numberOfLines = 2;
            button.layer.cornerRadius = 20 * DHFlexibleHorizontalMutiplier();
            button.titleLabel.font = [UIFont systemFontOfSize:14 * DHFlexibleHorizontalMutiplier()];
            button.clipsToBounds = YES;
//            button.backgroundColor = [UIColor greenColor];
            [button addTarget:self action:@selector(respondToParticpationButton:) forControlEvents:UIControlEventTouchUpInside];
            button;
        });
        
    }
    return _participationButton;


}
- (UIDynamicAnimator *)animator
{
    if (!_animator) {
        _animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
        
    }
    return _animator;

}

- (UIButton *)editButton
{
    if (!_editButton) {
        _editButton = ({
            
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setFrame:DHFlexibleFrame(CGRectMake(280, 25, 30, 30), YES)];
            [button setImage:[UIImage imageNamed:@"iconfont-bianji"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(respondToEditButton:) forControlEvents:UIControlEventTouchUpInside];

            button;
        });
    }
    return _editButton;

}
- (UIButton *)deleteButton
{
    if (!_deleteButton) {
        _deleteButton = ({
            
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setFrame:DHFlexibleFrame(CGRectMake(280, 30, 20, 20), YES)];
            [button setImage:[UIImage imageNamed:@"iconfont-close"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(respondToDeleteButton:) forControlEvents:UIControlEventTouchUpInside];
            button.hidden = YES;
            button;

        
        });
    }
    return _deleteButton;

}
@end
